package com.knowledgebase.lucene;

import java.nio.file.Paths;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;

public class LuceneUtils {
	private static Directory directory;
	private static Analyzer analyzer;
	static {
		try {
			directory = FSDirectory.open(Paths.get("./tmp/testindex"));
			// analyzer = new StandardAnalyzer();
			analyzer = new SmartChineseAnalyzer();
		} catch (Exception e) {
		}
	}
 
	public static Directory getDirectory() {
		return directory;
	}
 
	public static Analyzer getAnalyzer() {
		return analyzer;
	}
 
	public static void closeIndexWriter(IndexWriter indexWriter) {
		if (indexWriter != null) {
			try {
				indexWriter.close();
			} catch (Exception e2) {
			}
		}
	}

}
